{template 'header'}
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">日志中心</a>
        <a>
          <cite>任务完成日志</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so" id="search">
            注册时间:
            <input class="layui-input" autocomplete="off" placeholder="开始日" name="start_time" id="start_time"
                   value="{$_GPC['start_time']}">
            <input class="layui-input" autocomplete="off" placeholder="截止日" name="end_time" id="end_time"
                   value="{$_GPC['end_time']}">
            <input type="text" name="mobile" placeholder="请输入手机号" autocomplete="off" class="layui-input" id="mobile"
                   value="{$mobile}">
            <input type="text" name="truename" placeholder="请输入真实姓名" autocomplete="off" class="layui-input" id="truename"
                   value="{$truename}">
            <button class="layui-btn" lay-submit="" lay-filter="search"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>
    <xblock>
        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
        <button class="layui-btn"
                onclick="x_admin_show('添加用户','{php echo $this->createWebUrl('member_list',array('op'=>'add'))}')">
            <i class="layui-icon"></i>添加会员
        </button>
        <button class="layui-btn"
                onclick="x_admin_show('导入会员','{php echo $this->createWebUrl('member_import')}')">
            <i class="layui-icon"></i>导入会员
        </button>
        <button class="layui-btn layui-btn-radius" onclick="exportUser()"><i class="layui-icon"></i>导出Excel</button>
        <span class="x-right" style="line-height:40px">共有数据：{$total} 条</span>
    </xblock>
    <table class="layui-table x-admin">
        <thead>
        <tr>
            <th>
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i
                        class="layui-icon">&#xe605;</i></div>
            </th>
            <th>ID</th>
            <th>上级信息</th>
            <th>手机</th>
            <th>真实姓名</th>
            <th>账户余额</th>
            <th>支付宝姓名</th>
            <th>支付宝账号</th>
            <th>加入时间</th>
            <th>上次登录时间</th>
            <th>上次登录IP</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {loop $list $item}
        <tr>
            <td>
                <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='{$item["id"]}'><i
                        class="layui-icon">&#xe605;</i></div>
            </td>
            <td>{$item["id"]}</td>
            <td>
                {if $item["pid"]>0}
                {$item['pid']}|{$item['pmobile']}
                {/if}
            </td>
            <td>{$item["mobile"]}</td>
            <td>{$item["truename"]}</td>
            <td>{$item["user_money"]}</td>
            <td>{$item["alipay_name"]}</td>
            <td>{$item["alipay_account"]}</td>
            <td>{php echo date('Y-m-d H:i:s',$item["create_time"])}</td>
            <td>{php echo date('Y-m-d H:i:s',$item["last_login_time"])}</td>
            <td>{$item["last_login_ip"]}</td>
            <td class="td-status">
                {if $item['user_status'] == '0'}
                <span class="layui-btn layui-btn-disabled layui-btn-mini">禁用</span>
                {elseif $item['user_status'] == '1'}
                <span class="layui-btn layui-btn-normal layui-btn-mini">正常</span>
                {elseif $item['user_status'] == '2'}
                <span class="layui-btn layui-btn-warm layui-btn-mini">未验证</span>
                {else}
                <span class="layui-btn layui-btn-warm layui-btn-mini">待审</span>
                {/if}
            </td>
            <td class="td-manage">
                <a onclick="member_stop(this,'{$item['id']}')" href="javascript:;"
                   title="{if !$item['user_status']}启用{else}停用{/if}">
                    <i class="layui-icon">{if !$item['user_status']}&#xe601;{else}&#xe62f;{/if}</i>
                </a>
                <a title="编辑" onclick="x_admin_show('编辑','{php echo $this->createWebUrl('member_list',['op'=>'edit'])}',600,400)"
                   href="javascript:;">
                    <i class="layui-icon">&#xe642;</i>
                </a>
                <a onclick="x_admin_show('修改密码','{php echo $this->createWebUrl('member_list',['op'=>'edit'])}',600,400)"
                   title="修改密码" href="javascript:;">
                    <i class="layui-icon">&#xe631;</i>
                </a>
                <a title="删除" onclick="member_del(this,'要删除的id')" href="javascript:;">
                    <i class="layui-icon">&#xe640;</i>
                </a>
            </td>
        </tr>
        {/loop}
        </tbody>
    </table>
    <div class="page">
        {$pager}
    </div>
</div>
<script>
    layui.use('form', function () {
        var form = layui.form;

        //监听提交
        form.on('submit(search)', function (data) {
            console.log(data.field)
            var str = '';
            for (var key in data.field) {
                str += key + "=" + data.field[key] + "&";
            }
            var url = '{php echo $this->createWebUrl("member_list")}'
            location.href = url + "&" + str;
            return false;
        });
    });

    function exportUser(){
        var str = $('#search').serialize()
        var ids = tableCheck.getData();
        var url = '{php echo $this->createWebUrl("member_export")}'
        location.href = url + "&" + str + "&ids=" + ids;
    }

    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#start_time' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end_time' //指定元素
        });
    });


    /*用户-停用*/
    function member_stop(obj, id) {
        var url = '{php echo $this->createWebUrl("member_list",array("op"=>"ting"))}'
        if ($(obj).attr('title') == '启用') {
            layer.confirm('确认要启用吗？', function (index) {
                $.post(url, {id: id, yes: 1}, function (ret) {
                    if (ret.code) {
                        //发异步把用户状态进行更改
                        $(obj).attr('title', '停用')
                        $(obj).find('i').html('&#xe601;');

                        $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已启用');
                        layer.msg('已启用!', {icon: 1, time: 1000});
                    } else {
                        layer.msg(ret.msg, {icon: 0});
                    }
                }, 'json')
            })
        } else {
            layer.confirm('确认要停用吗？', function (index) {
                $.post(url, {id: id, yes: 0}, function (ret) {
                    if (ret.code) {
                        $(obj).attr('title', '启用')
                        $(obj).find('i').html('&#xe62f;');

                        $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已停用');
                        layer.msg('已停用!', {icon: 1, time: 1000});
                    } else {
                        layer.msg(ret.msg, {icon: 0});
                    }
                }, 'json')
            })
        }
    }

    /*用户-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            //发异步删除数据
            var url = '{php echo $this->createWebUrl("member_list",array("op"=>"del"))}'
            $.post(url, {id}, function (ret) {
                if (ret.code) {
                    $(obj).parents("tr").remove();
                    layer.msg(ret.msg, {icon: 1, time: 1000});
                } else {
                    layer.msg(ret.msg, {icon: 0});
                }
            }, 'json')
        });
    }


    function delAll(argument) {

        var data = tableCheck.getData();

        layer.confirm('确认要删除吗？' + data, function (index) {
            //捉到所有被选中的，发异步进行删除
            var url = '{php echo $this->createWebUrl("member_list",array("op"=>"del"))}'
            $.post(url, {'ids': data}, function (ret) {
                console.log(ret)
                if (ret.code) {
                    layer.msg(ret.msg, {icon: 1});
                    $(".layui-form-checked").not('.header').parents('tr').remove();
                } else {
                    layer.msg(ret.msg, {icon: 0});
                }
            }, 'json')
        });
    }
</script>
<script>var _hmt = _hmt || [];
(function () {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>
</body>

</html>